Skip to content

Avoid THP compaction stalls in eos::map_host and report offload startup timings - #625

Open
flare-autobot wants to merge 1 commit into
NVIDIA:mainfrom
flare-autobot:fix/issue-616-host-slab-thp-fallback-timings
Open

flare-autobot wants to merge 1 commit into
NVIDIA:mainfrom
flare-autobot:fix/issue-616-host-slab-thp-fallback-timings

Conversation

@flare-autobot

@flare-autobot flare-autobot commented Nov 30, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #616

Why

Serving a model with a large contiguous host prefix-cache slab on Linux (--prefix-cache-memory combined with --prefix-cache-disk, --prefix-cache-pool, --lossless-kv-compression, or non-VMM host fallback) can stall startup in Prepare host prefix cache for more than 15 minutes when physical memory is fragmented. Flare allocates contiguous host slabs through eos::map_host (eos/src/unix.rs), which is called by SlabPool::new (selene/src/slab.rs) and remote pool staging (Region::anonymous in selene/src/pool/shm.rs). Advising MADV_HUGEPAGE over the entire anonymous mapping and prefaulting it in one madvise(MADV_POPULATE_WRITE) call instructs Linux to run synchronous direct reclaim and memory compaction (__GFP_DIRECT_RECLAIM) on every fault under THP defrag=madvise, defer+madvise, or always once contiguous PMD-sized blocks (2 MiB on 4 KiB kernels) are exhausted. Issuing one monolithic prefault also holds the process's mmap_lock across sustained compaction stalls and degrades host responsiveness. At the same time, NativeModel::prepare_offload (helios/src/runtime_core/model.rs) wrapped slab population, CUDA host registration (cuMemHostRegister_v2), and disk record scanning inside one Prepare host prefix cache phase without intermediate step status or separate elapsed durations, preventing operators from separating host slab population time from CUDA registration time.

Inspecting Linux THP sysfs policy directly in eos::map_host avoids requiring a host-wide sysctl change (which needs elevated privileges and affects unrelated processes) or adding runtime switches. Under synchronous-compaction policies, probing bounded PMD-aligned chunks against /proc/buddyinfo free hugepage supply (filtered by process Mems_allowed_list from /proc/self/status), chunk fault latency, and consecutive /proc/vmstat compact_stall increments claims huge pages while contiguous blocks are free and switches promptly to base pages before prolonged compaction occurs. Because cuMemHostRegister_v2 and RDMA ibv_reg_mr operate over the slab mapping, pre-anchoring one shared anon_vma on the unsplit mapping before any sub-range MADV_HUGEPAGE and issuing one whole-range madvise once populated lets Linux vma_merge collapse all sub-VMAs back into one single contiguous VMA even after a mid-slab fallback.

What Changed

  • Host slab allocator (eos/src/unix.rs):
    • Before: map_host did not reject zero-byte requests, unconditionally issued madvise(MADV_HUGEPAGE) over [ptr, ptr + bytes), prefaulted the entire range in one madvise(MADV_POPULATE_WRITE) call, and fell back to a byte-wise volatile write loop on any non-zero madvise return without unmapping on fatal errors.
    • After: map_host keeps its pub fn map_host(bytes: usize) -> io::Result<usize> signature, rejects bytes == 0 with EINVAL, wraps the mmap allocation in an RAII MappingGuard that calls munmap on any population error, retries MADV_POPULATE_WRITE on EINTR, falls back to page-strided volatile zero writes only on EINVAL or ENOSYS, propagates all other errnos cleanly, and populates in bounded 64 MiB chunks across all Unix modes. On Linux, it reads /sys/kernel/mm/transparent_hugepage/{enabled,defrag,hpage_pmd_size} (validating power-of-two hpage_pmd_size > page_size() and deriving portable 2 MiB, 32 MiB, or 512 MiB defaults for 4 KiB, 16 KiB, or 64 KiB kernels when hpage_pmd_size is unreadable):
      • enabled=never: populates in bounded 64 MiB base-page chunks without THP advice.
      • defrag=defer or never: advises MADV_HUGEPAGE once upfront and populates in bounded 64 MiB chunks.
      • enabled=always with defrag=madvise or defer+madvise: omits MADV_HUGEPAGE and populates in bounded 64 MiB chunks using the kernel's non-blocking opportunistic path.
      • Synchronous-compaction policies (enabled=madvise with defrag=madvise|defer+madvise|always, enabled=always with defrag=always, or unknown policy): pre-anchors one shared anon_vma on the unsplit mapping (advising MADV_NOHUGEPAGE over the unsplit mapping first when default faults can synchronously compact, and shrinking the PMD-aligned interior by one PMD when both endpoints are PMD-aligned), walks growing PMD-aligned chunks from hpage_pmd_size up to max(16 MiB, hpage_pmd_size) while checking order-weighted free huge pages in /proc/buddyinfo (Normal and Movable zones, or all zones when absent, restricted to NUMA nodes allowed by /proc/self/status Mems_allowed_list when readable), chunk latency (stall_floor = max(15 ms, chunk_bytes / 1 GiB/s), hard_ceiling = max(50 ms, chunk_bytes / 256 MiB/s)), and /proc/vmstat compact_stall (requiring 2 consecutive CheckCompactStall chunks with advancing compact_stall to resist host-wide noise while keeping hard_ceiling as an immediate 1-chunk breaker), falls back to 64 MiB base-page chunks when free huge pages drop below chunk_hugepages + (total_hugepages / 16).min(32) or compaction stalls occur, and finishes with one whole-range madvise (MADV_NOHUGEPAGE after fallback, MADV_HUGEPAGE otherwise) so Linux merges all sub-VMAs back into one contiguous VMA.
  • Offload startup timings and live progress (selene/src/offload.rs, selene/src/offload/tests.rs, helios/src/offload/mod.rs, helios/src/runtime_core/model.rs):
    • Before: prepare_with_inputs_budget recorded no per-step timings and emitted no intermediate progress steps; Prepared::summary() reported slab size, slot count, CPU input limits, and disk directory metadata without elapsed durations.
    • After: selene/src/offload.rs adds PrepareTimings (slab_populate, cuda_register, disk_scan, each Option<Duration>) to Prepared and adds prepare_with_inputs_budget_with_progress(..., on_step: impl FnMut(&str)) while preserving existing prepare_with_inputs and prepare_with_inputs_budget signatures. The contiguous populate and CUDA registration sequence is shared in a single path for both split-by-rank fallback (SlabPool::try_sized_by_rank returning Ok(None)) and non-split slabs, resetting progress steps and timers before SlabPool::sized and before pool.register. Prepared::summary() appends allocate X.Xs (split-by-rank pools), populate X.Xs, register Y.Ys (contiguous registered pools), and scan Z.Zs (disk tiers) inside existing parenthetical clauses while leaving restore-only and disabled summaries byte-for-byte unchanged. helios/src/offload/mod.rs re-exports PrepareTimings and prepare_with_inputs_budget_with_progress (keeping prepare_with_inputs_budget for pub fn parity with selene::offload), and NativeModel::prepare_offload forwards step labels to phase.detail(step) while keeping the Prepare host prefix cache label and StartupStage::PrepareHostPrefixCache identifier unchanged.
  • Documentation & follow-up tracking (docs/prefix-cache-offload.md, docs/TODO.txt): Updated sections 2.5 and 2.11 to clarify Unix-only bounded chunking, Linux policy-aware slab population (including Mems_allowed_list NUMA filtering and consecutive compact_stall confirmation), single-VMA merging before registration, live step details, and per-step startup timings. Recorded follow-up end-to-end flare run A/B, live RDMA ibv_reg_mr, 16 KiB/64 KiB ARM64 kernel checks, and a selene-manager/src/arena.rs MADV_HUGEPAGE audit in docs/TODO.txt.
  • Compatibility & lifetimes: No Protobuf schema, model core format, or serving ABI changed; signed model cores load without re-export. Prepared::summary() appends elapsed timing tokens (allocate/populate/register/scan) inside existing parenthetical clauses, and bounded 64 MiB prefault chunking applies across all Unix modes. Every returned slab mapping remains zeroed, prefaulted writable, page-aligned, single-VMA, and unregistered before munmap on drop.

Claimed Benefit

  • Measured result (two-NUMA x86_64 Linux 6.8 + discrete SM120 GPU): Under Linux THP enabled=madvise, defrag=madvise, and fragmented physical memory (~12.4 GiB free order-9/10 blocks across both Normal zones out of 236.8 GiB available RAM), populating a 48 GiB anonymous host slab dropped from 128.56 s (compact_stall +25,654 with the prior MADV_HUGEPAGE + monolithic MADV_POPULATE_WRITE sequence) to 30.99 s (compact_stall +62, 4.15x faster, 1 merged VMA, AnonHugePages=2,046 MiB, VmFlags nh). Once contiguous huge pages were free after the baseline run, eos::map_host(48 GiB) completed in 13.78 s with AnonHugePages=43,230 MiB (90% huge pages, 1 VMA). At the 119 GiB slab size reported in v0.4.4 takes over 15 minutes to prepare a 119 GiB host prefix cache on fragmented Linux memory #616, eos::map_host(119 GiB) populated in 57.19 s (compact_stall +2,031, 1 merged VMA, AnonHugePages=43,454 MiB, VmFlags nh) and registered with discrete SM120 cuMemHostRegister_v2 in 11.27 s (68.46 s combined), passing a 4 MiB H2D/D2H CUDA DMA round-trip from the THP head through GPU memory to the base-page tail.
  • Expected benefit (not yet timed inside a live flare run launch): Operators running flare run with large host prefix-cache slabs see live sub-step progress updates and separate allocate/populate/register/scan durations in Prepare host prefix cache.

Supporting Evidence & Material Limitations

Checks Executed

Linux ARM64 SM121 (NVIDIA GB10, Linux 7.0.0-1025-nvidia, rebased onto origin/main 8da73911) (4 KiB base pages, 2 MiB hpage_pmd_size, THP enabled=madvise, defrag=madvise, single NUMA Node 0):

  • Host allocator contract, Linux THP/NUMA parsing, and /proc/self/smaps single-VMA merging:
    • cargo test --locked --release --manifest-path eos/Cargo.toml --target-dir flare-cli/target -- --nocapture: 12 passed, 0 failed, 0 warnings. Covers EINVAL on 0 bytes, MappingGuard munmap on population error, sysfs THP/PMD parsing (4 KiB/16 KiB/64 KiB layouts), the 24-cell (enabled, defrag) mode matrix, order-weighted /proc/buddyinfo parsing with /proc/self/status Mems_allowed_list NUMA node filtering and saturating arithmetic, /proc/vmstat compact_stall parsing, reserve and latency thresholds, synthetic EagerHugepage vs BasePages VmFlags assertions (populate_linux_applies_eager_and_base_page_policies), live /proc/self/smaps single-VMA merging (map_host_advises_hugepages_and_prefaults_zeroed_pages), and forced mid-mapping MADV_HUGEPAGE-to-base-page fallback merging into one VMA (adaptive_mid_mapping_fallback_merges_into_single_vma).
  • Offload timing, progress step reporting, and RDMA feature compilation:
    • cargo test --locked --release --manifest-path selene/Cargo.toml --features test-support --target-dir flare-cli/target: 552 unit tests and 1 integration test passed, including unit tests covering split-by-rank, split-fallback-to-contiguous (UnsupportedSplitRegistrar), contiguous + disk, and restore-only timings, emitted step sequences, and Prepared::summary() formatting.
    • cargo check --locked --manifest-path selene/Cargo.toml --tests --features rdma --target-dir flare-cli/target: passed.
  • Downstream runtime and CLI crates:
    • FLARE_TEST_TEMPLATE_DIR=<prepared-templates> cargo test --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server --target-dir flare-cli/target: 1,748 lib tests passed (0 failed, 46 ignored) and 62 integration tests passed (0 failed; checkpoint-gated tests ignored).
    • FLARE_TEST_TEMPLATE_DIR=<prepared-templates> cargo test --locked --release --manifest-path flare/Cargo.toml --target-dir flare-cli/target: 245 passed (4 ignored).
    • FLARE_TEST_TEMPLATE_DIR=<prepared-templates> cargo test --locked --release --manifest-path flare-cli/Cargo.toml: 227 passed (3 ignored).
  • CUDA host registration and mixed-VMA DMA round-trip (NVIDIA GB10 SM121, prior to rebase onto 8da73911; allocator VMA/DMA contract unchanged):
    • FLARE_RUN_CUDA_TESTS=1 cargo test --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server --target-dir flare-cli/target -- --ignored host_registration_unregisters_when_dropped_on_another_thread --nocapture: passed (registration, cross-thread drop unregistration, and re-registration of an eos::map_host mapping).
    • FLARE_RUN_CUDA_TESTS=1 cargo test --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server --target-dir flare-cli/target -- --ignored batched_copies_round_trip_through_registered_memory --nocapture: passed (8 MiB eos::map_host mapping; blocking event wait 85.36 ms wall, 37.82 us thread CPU).
    • Direct CUDA driver check (cuMemHostRegister_v2, cuMemcpyHtoD_v2, cuMemcpyDtoH_v2) under THP enabled=madvise, defrag=madvise: passed on pure-THP (16 MiB, 1 VMA, AnonHugePages=16384 kB, VmFlags hg), pure-base-page (16 MiB, 1 VMA, AnonHugePages=0 kB, VmFlags nh), and a mixed THP-prefix plus base-page-tail merged mapping replicating adaptive fallback (32 MiB, 1 VMA, AnonHugePages=8192 kB, VmFlags nh).

Two-NUMA x86_64 Linux 6.8.0-151-generic + discrete NVIDIA RTX PRO 6000 Blackwell Max-Q (SM120) (4 KiB base pages, 2 MiB hpage_pmd_size, THP enabled=madvise, defrag=madvise, initial free huge pages: Node 0 Normal order-9=1,892, order-10=1,860; Node 1 Normal order-9=338, order-10=311):

  • Standalone eos::map_host vs prior MADV_HUGEPAGE + MADV_POPULATE_WRITE A/B and discrete SM120 cuMemHostRegister_v2 + DMA round-trip benchmark:
    • FIXED_48G_1 (fragmented cold start): populate 30.988 s, compact_stall +62, vmas=1, AnonHugePages=2,046 MiB, VmFlags nh; cuMemHostRegister_v2(48 GiB, PORTABLE) 9.483 s (rc=0); 4 MiB head->SM120->tail DMA round-trip passed.
    • OLD_V044_48G (prior path): populate 128.558 s, compact_stall +25,654, vmas=1, AnonHugePages=41,336 MiB, VmFlags hg.
    • FIXED_48G_2 (post-compaction with huge pages available): populate 13.780 s, compact_stall +2,039, vmas=1, AnonHugePages=43,230 MiB, VmFlags nh.
    • FIXED_119G: populate 57.189 s, compact_stall +2,031, vmas=1, AnonHugePages=43,454 MiB, VmFlags nh; cuMemHostRegister_v2(119 GiB, PORTABLE) 11.274 s (rc=0); 4 MiB head->SM120->tail DMA round-trip passed.

Unrun Checks & Material Limitations

  • End-to-end flare run with exported core (tracked in docs/TODO.txt): Full flare run <exported-core> --prefix-cache-memory <size> --prefix-cache-disk <dir> and tests/server/test_prefix_cache_offload.py remain unrun because native helios/flare-cli compilation on the discrete SM120 host lacked cmake for turbojpeg-sys and the SM121 host had no exported model cores.
  • Additional kernel/hardware configurations (tracked in docs/TODO.txt): Live RDMA ibv_reg_mr registration, 16 KiB/64 KiB ARM64 Linux kernels, and kernels without CONFIG_TRANSPARENT_HUGEPAGE were verified through deterministic parser and policy unit tests rather than live hardware execution.
  • Ignored/skipped tests: Checkpoint-gated helios integration tests and torch-dependent native_pixels_match_canonical_torchvision_processor were skipped on the SM121 test host because checkpoints and a PyTorch environment were not present there.

Discord: flare-autobot

@flare-autobot

Copy link
Copy Markdown
Collaborator Author

A case file has been opened for 625.
Case File Intake Report

Future reviews will auto-run 90 minutes after code updates are pushed.

  • Re-review sooner: Call @flare-autobot after push.
  • Opt-out: Include #autobot:ignore in the PR or any comment.

@flare-autobot flare-autobot added area:memory Memory budgets, allocation lifetimes, scratch sharing, and capacity. area:selene Selene shared prefix-cache pool, protocol, manager, and transfers. bug Something isn't working performance Performance, latency, throughput, or memory-efficiency investigation or improvement. priority:P2 Normal bug priority: workflow failure or diagnosis with narrower impact or an available workaround. triage:review Proposed change needs code review; this does not imply merge readiness. labels Nov 30, 2026
@flare-autobot

Copy link
Copy Markdown
Collaborator Author

Autobot Review

Full Review · Value Proposition · Case File

Recommendation: Changes Requested

The allocator rewrite in eos/src/unix.rs and the startup timing/progress plumbing in selene/helios are sound and directly fix the #616 THP compaction stall, but CI is failing on head 9639e57, the Charter #210 served flare run verification is neither run nor recorded in docs/TODO.txt, and a few targeted guard/dedup items remain.

  • Blockers: 1 · Should fix: 3 · Subtract/Simplify: 2 · Nits: 5
Walkthrough
  • eos/src/unix.rs:86-680: Rewrites map_host behind map_host_with + RAII MappingGuard (unmaps on population error, rejects bytes == 0 with EINVAL), retries MADV_POPULATE_WRITE on EINTR with volatile-write fallback only on EINVAL/ENOSYS, and adds Linux THP sysfs detection (enabled, defrag, hpage_pmd_size with 2/32/512 MiB portable defaults) selecting among BasePages, EagerHugepage, KernelDefaultOpportunistic, and AdaptiveHugepage (PMD-aligned chunks up to max(16 MiB, hpage_pmd_size), /proc/buddyinfo reserve checks, chunk latency + /proc/vmstat compact_stall fallback to 64 MiB base-page chunks, final whole-range madvise VMA merge). Adds ~440 lines of unit and live /proc/self/smaps tests (:769-1202).
  • selene/src/offload.rs:328-480, 573-795: Adds PrepareTimings (slab_populate, cuda_register, disk_scan) to Prepared, adds prepare_with_inputs_budget_with_progress(..., on_step: impl FnMut(&str)) while keeping existing entry points, instruments split allocation, split→contiguous fallback, contiguous populate/CUDA registration, and disk scanning, and appends allocate/populate/register/scan durations to Prepared::summary().
  • selene/src/offload/tests.rs:1107-1380: Four unit tests covering split-by-rank, split→contiguous fallback, contiguous+disk, and restore-only step sequences, timings, and summary strings.
  • helios/src/offload/mod.rs:30-33, 82-120 & helios/src/runtime_core/model.rs:966-980: Re-exports PrepareTimings, forwards prepare_with_inputs_budget_with_progress, and wires |step| phase.detail(step) into NativeModel::prepare_offload without changing the Prepare host prefix cache phase label or StartupStage.
  • docs/prefix-cache-offload.md:516-535, 986-995: Documents the Linux THP policy-aware population and single-VMA merging (§2.5) and the live step details and per-step timings (§2.11).
Merge Risk: Medium · up to 9639e57
  • Shared allocator blast radius (eos/src/unix.rs): Every host prefix-cache slab (selene/src/slab.rs:164), remote pool staging buffer (selene/src/pool/shm.rs:78), and CUDA host-registration test (helios/src/cuda.rs:1599 (not opened),1665) allocates through eos::map_host. The policy matrix, chunked MADV_POPULATE_WRITE, RAII MappingGuard, and single-VMA merge geometry are verified sound, but the Linux-specific adaptive heuristics have no runtime override and CI is currently failing on head 9639e57.
  • Single-VMA & lifetime invariants preserved: Pre-anchoring one shared anon_vma on the unsplit mapping (eos/src/unix.rs:531-550) keeps peak VMA count at most 3 during the adaptive loop and collapses back to 1 VMA before cuMemHostRegister_v2/ibv_reg_mr (eos/src/unix.rs:609-616). MappingGuard (:139-181) prevents leaked mappings on population errors.
  • Cross-PR overlap & observability: Open PRs Pin Helios execution and RoCE proxy threads to high-capacity CPUs on asymmetric Linux topologies #576 (eos/src/unix.rs) and Make the system headroom of unified-memory cache sizing configurable #323 (selene/src/offload.rs, selene/src/offload/tests.rs, helios/src/offload/mod.rs, helios/src/runtime_core/model.rs, docs/prefix-cache-offload.md) overlap on the same files and the prepare_with_inputs* signature family. Prepared::summary() appends elapsed durations inside existing parenthetical clauses (selene/src/offload.rs:415-475); no in-repo test asserts the old text.
Pre-merge checks: ✅ 1 passed · ⚠️ 3 warnings

Have your agent review the Full Review for complete verified findings, file:line citations, and suggested changes.

To opt out, include #autobot:ignore in your post or comment.

…up timings

Large contiguous host prefix-cache slabs allocated via `eos::map_host` on Linux
can stall startup in `Prepare host prefix cache` for more than 15 minutes when
physical memory is fragmented. Unconditionally issuing `madvise(MADV_HUGEPAGE)`
over the entire mapping and prefaulting it in one `MADV_POPULATE_WRITE` call
drives Linux synchronous direct reclaim and memory compaction on every fault
under THP `defrag=madvise`, `defer+madvise`, or `always` once contiguous PMD
blocks are exhausted, while holding `mmap_lock` for the full stall. Meanwhile,
`NativeModel::prepare_offload` wrapped slab allocation/population, CUDA host
registration, and disk scanning inside a single opaque phase without live step
status or per-step durations. Inspecting Linux THP sysfs policy directly in
`eos::map_host`, checking `/proc/buddyinfo` (filtered by process
`Mems_allowed_list`), fault latency, and consecutive `/proc/vmstat`
`compact_stall` increments, and collapsing sub-VMAs back into one contiguous
VMA before registration eliminates prolonged compaction stalls without runtime
switches or host-wide sysctl changes.

Before this change:
- `eos::map_host` (`eos/src/unix.rs`) did not reject `bytes == 0`, advised
  `MADV_HUGEPAGE` over the entire mapping unconditionally, prefaulted the whole
  range in one `MADV_POPULATE_WRITE` call, and fell back to a byte-wise
  volatile write loop on any non-zero `madvise` return without unmapping on
  fatal errors.
- `selene::offload::prepare_with_inputs_budget` (`selene/src/offload.rs`)
  recorded no per-step timings and emitted no intermediate progress steps;
  `Prepared::summary()` reported slab and disk metadata without elapsed
  durations.

After this change:
- `eos::map_host` (`eos/src/unix.rs`) preserves its public signature, rejects
  `bytes == 0` with `EINVAL`, wraps the mapping in an RAII `MappingGuard` that
  calls `munmap` on population failure, retries `MADV_POPULATE_WRITE` on
  `EINTR`, falls back to page-strided volatile zero writes only on `EINVAL` or
  `ENOSYS`, and populates in bounded 64 MiB chunks across Unix modes. On Linux,
  it reads `/sys/kernel/mm/transparent_hugepage/{enabled,defrag,hpage_pmd_size}`
  (with 2/32/512 MiB portable defaults for 4/16/64 KiB base pages):
  - `enabled=never`: bounded 64 MiB base-page chunks without THP advice.
  - `defrag=defer|never`: upfront `MADV_HUGEPAGE` + bounded 64 MiB chunks.
  - `enabled=always` with `defrag=madvise|defer+madvise`: bounded 64 MiB chunks
    relying on the kernel's non-blocking opportunistic hugepage path.
  - Synchronous-compaction policies (`enabled=madvise` with
    `defrag=madvise|defer+madvise|always`, `enabled=always` with
    `defrag=always`, or unknown): pre-anchors one shared `anon_vma` on the
    unsplit mapping (advising `MADV_NOHUGEPAGE` first when default faults can
    synchronously compact), walks growing PMD-aligned chunks up to
    `max(16 MiB, hpage_pmd_size)` while checking order-weighted free huge pages
    in `/proc/buddyinfo` restricted to NUMA nodes allowed by
    `/proc/self/status` (`Mems_allowed_list`, falling back to all nodes when
    unreadable), chunk latency (`stall_floor` / `hard_ceiling`), and 2
    consecutive `CheckCompactStall` chunks with advancing `/proc/vmstat`
    `compact_stall` (keeping `hard_ceiling` as an immediate 1-chunk breaker),
    falls back to 64 MiB base-page chunks when huge pages are scarce or
    compaction stalls begin, and applies one whole-range `madvise`
    (`MADV_NOHUGEPAGE` after fallback, `MADV_HUGEPAGE` otherwise) once all
    pages are populated so Linux merges the mapping back into one contiguous
    VMA before CUDA or RDMA registration.
- `selene/src/offload.rs` adds `PrepareTimings` (`slab_populate`,
  `cuda_register`, `disk_scan`) to `Prepared` and
  `prepare_with_inputs_budget_with_progress(..., on_step)` while retaining
  existing `prepare_with_inputs` and `prepare_with_inputs_budget` entry points,
  sharing one contiguous populate/register path for split fallback and
  non-split slabs. `Prepared::summary()` appends `allocate X.Xs`,
  `populate X.Xs, register Y.Ys`, and `scan Z.Zs` inside existing parenthetical
  clauses while leaving restore-only and disabled summaries unchanged.
- `helios/src/offload/mod.rs` re-exports `PrepareTimings` and
  `prepare_with_inputs_budget_with_progress`, and
  `NativeModel::prepare_offload` (`helios/src/runtime_core/model.rs`) forwards
  step labels to `phase.detail(step)`.
- `docs/prefix-cache-offload.md` specifies Unix bounded chunking, Linux
  policy-aware slab population (including `Mems_allowed_list` NUMA filtering
  and consecutive `compact_stall` confirmation), single-VMA merging, and live
  step timings. `docs/TODO.txt` tracks follow-up end-to-end `flare run` A/B,
  live RDMA `ibv_reg_mr`, 16 KiB/64 KiB kernel validation, and
  `selene-manager/src/arena.rs` audit.

Result: On a two-NUMA x86_64 Linux 6.8 host with a discrete SM120 GPU under THP
`enabled=madvise, defrag=madvise` and fragmented memory (~12.4 GiB free
order-9/10 blocks across both `Normal` zones), populating a 48 GiB host slab
dropped from 128.56 s (`compact_stall` +25,654) to 30.99 s (`compact_stall`
+62, 4.15x faster, 1 merged VMA, `AnonHugePages=2,046 MiB`), completed in
13.78 s with 90% THP once contiguous huge pages were free, and populated plus
registered a 119 GiB slab with `cuMemHostRegister_v2` in 68.46 s combined
(57.19 s populate + 11.27 s register, 1 VMA, 4 MiB H2D/D2H DMA round-trip
passed). No Protobuf schema, model core format, or serving ABI changed.

Evidence:
- Linux ARM64 SM121 (Linux 7.0.0-1025-nvidia, rebased onto `origin/main`):
  - `cargo test --locked --release --manifest-path eos/Cargo.toml --target-dir flare-cli/target`:
    12 passed, 0 failed (including NUMA `Mems_allowed_list` filtering,
    synthetic `EagerHugepage`/`BasePages` `/proc/self/smaps` policy assertions,
    and single-VMA merge checks).
  - `cargo test --locked --release --manifest-path selene/Cargo.toml --features test-support --target-dir flare-cli/target`:
    552 unit tests + 1 integration test passed; `cargo check --tests --features rdma` passed.
  - `cargo test --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server --target-dir flare-cli/target`:
    1,810 passed, 0 failed, 83 ignored (1,748 lib + 62 integration).
  - `cargo test --locked --release --manifest-path flare/Cargo.toml --target-dir flare-cli/target`:
    245 passed, 0 failed, 4 ignored.
  - `cargo test --locked --release --manifest-path flare-cli/Cargo.toml`:
    227 passed, 0 failed, 3 ignored.
  - CUDA host registration ignored tests (`host_registration_unregisters_when_dropped_on_another_thread`,
    `batched_copies_round_trip_through_registered_memory`) and direct
    `cuMemHostRegister_v2` + H2D/D2H DMA check on pure-THP, pure-base-page, and
    mixed THP-head/base-tail merged VMAs passed on NVIDIA GB10 SM121.
- Two-NUMA x86_64 Linux 6.8 + discrete SM120 GPU:
  - Standalone `eos::map_host` vs prior `MADV_HUGEPAGE` + `MADV_POPULATE_WRITE`
    A/B (48 GiB fragmented/post-compaction and 119 GiB) plus `cuMemHostRegister_v2`
    and 4 MiB H2D/D2H DMA round-trip passed.

Limitations and unrun checks (also recorded in `docs/TODO.txt`):
- End-to-end `flare run <core> --prefix-cache-memory ... --prefix-cache-disk ...`
  and `tests/server/test_prefix_cache_offload.py` were not run because the
  discrete SM120 host lacked `cmake` for `turbojpeg-sys` and the SM121 host had
  no exported model cores.
- Live RDMA `ibv_reg_mr`, 16 KiB/64 KiB ARM64 kernels, and kernels without
  `CONFIG_TRANSPARENT_HUGEPAGE` were verified via deterministic unit tests
  rather than live hardware execution.
- Checkpoint-gated `helios` integration tests and torch-dependent vision tests
  were skipped on the SM121 host.

Signed-off-by: yatesdr <6937857+yatesdr@users.noreply.github.com>
Design-Signed-Off-By: yatesdr; design-review=2e5b
@yatesdr
yatesdr force-pushed the fix/issue-616-host-slab-thp-fallback-timings branch from 9639e57 to f2d03bc Compare November 30, 2026 13:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:memory Memory budgets, allocation lifetimes, scratch sharing, and capacity. area:selene Selene shared prefix-cache pool, protocol, manager, and transfers. bug Something isn't working performance Performance, latency, throughput, or memory-efficiency investigation or improvement. priority:P2 Normal bug priority: workflow failure or diagnosis with narrower impact or an available workaround. triage:review Proposed change needs code review; this does not imply merge readiness.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

v0.4.4 takes over 15 minutes to prepare a 119 GiB host prefix cache on fragmented Linux memory

2 participants